home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CColorPicker 1.0 / CColorPicker.c next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  2.1 KB  |  133 lines  |  [TEXT/KAHL]

  1. /***
  2.  * CColorPicker.c
  3.  *
  4.  *        by Bernie Bernstein (bernard@cs.colorado.edu)
  5.  *
  6.  *        SUPERCLASS = CPane
  7.  *
  8.  *        pick a color when this control is clicked on.
  9.  *        display its color.
  10.  ***/
  11.  
  12. #include <Global.h>
  13. #include <Picker.h>
  14.  
  15. #include "CColorPicker.h"
  16.  
  17. /***
  18.  * IColorPicker
  19.  *
  20.  *        Initialize the color picker
  21.  ***/
  22. void CColorPicker::IColorPicker(CView *anEnclosure, CBureaucrat *aSupervisor,
  23.                             short aWidth, short aHeight, short aHEncl, short aVEncl,
  24.                             SizingOption aHSizing, SizingOption aVSizing)
  25. {
  26.     CPane::IPane(anEnclosure, aSupervisor, aWidth, aHeight, aHEncl, aVEncl,
  27.                     aHSizing, aVSizing);
  28.     
  29.     prompt[0] = '\0';
  30.     SetWantsClicks( TRUE);
  31. }
  32.  
  33.  
  34. /***
  35.  * IViewTemp
  36.  *
  37.  *        Initialize the color picker from the view template resource
  38.  ***/
  39. void CColorPicker::IViewTemp( CView *anEnclosure, CBureaucrat *aSupervisor,
  40.                                 Ptr viewData)
  41. {
  42.     inherited::IViewTemp( anEnclosure, aSupervisor, viewData);
  43. }
  44.  
  45. /***
  46.  * SetMessage
  47.  *
  48.  *        Set the message to show in the color picker.
  49.  ***/
  50. void CColorPicker::SetPrompt(ConstStr255Param msg)
  51. {
  52.     CopyPString(msg, prompt);
  53. }
  54.  
  55.  
  56. /***
  57.  * SetCurrentColor
  58.  *
  59.  *        Set the current color.
  60.  ***/
  61. void CColorPicker::SetCurrentColor(RGBColor aColor)
  62. {
  63.     currentColor = aColor;
  64.     Refresh();
  65. }
  66.  
  67.  
  68. /***
  69.  * GetCurrentColor
  70.  *
  71.  *        Get the current color
  72.  ***/
  73. RGBColor CColorPicker::GetCurrentColor(void)
  74. {
  75.     return currentColor;
  76. }
  77.  
  78.  
  79. /***
  80.  * DoClick
  81.  *
  82.  *        When the picker is clicked, bring up the standard color picker dialog.
  83.  ***/
  84. void CColorPicker::DoClick( Point hitPt, short modifierKeys, long when)
  85. {
  86.     if (gSystem.hasColorQD)
  87.         {
  88.         Boolean gotColor;
  89.         Point pos;
  90.         RGBColor newColor;
  91.         pos.h = pos.v = 0;
  92.         gotColor = GetColor(pos, prompt, ¤tColor, &newColor);
  93.         if (gotColor)
  94.             {
  95.             SetCurrentColor(newColor);
  96.             }
  97.         }
  98.     else
  99.         {
  100.         }
  101. }
  102.  
  103.  
  104. /***
  105.  * Draw
  106.  *
  107.  *        Draw the color
  108.  ***/
  109. void CColorPicker::Draw( Rect *area)
  110. {
  111.     RGBColor saveColor;
  112.     
  113.     if (gSystem.hasColorQD)
  114.         {
  115.         GetForeColor(&saveColor);
  116.         RGBForeColor(¤tColor);
  117.         PaintRect( area);
  118.         RGBForeColor(&saveColor);
  119.         }
  120.     else
  121.         {
  122.         PenPat (gray);
  123.         PenMode(patBic);
  124.         PaintRect( area);
  125.         PenNormal();
  126.         }
  127. }
  128.  
  129.  
  130.  
  131.  
  132.  
  133.